package com.example.designpattern.responsibility_three.validator;

import com.example.designpattern.responsibility_three.AbstractValidator;
import com.example.model.GoodsDTO;
import org.springframework.stereotype.Service;

/**
 * 库存校验
 *
 * @author long
 * @date 2024/4/20 10:43
 */
@Service
public class StockValidator extends AbstractValidator {

    @Override
    public void doValidate(GoodsDTO dto) {
        if(dto.getStockQty() <= 0){
            throw new RuntimeException("库存数量必须大于0");
        }
    }

    @Override
    protected void preValidate(GoodsDTO dto) {
        logger.info("----------库存数量校验开始----------");
    }

    @Override
    protected void postValidate(GoodsDTO dto) {
        logger.info("----------库存数量校验结束----------");
    }

    @Override
    public int getPriority() {
        return 3;
    }
}
